/**
 * Plotter 负责管理与前端画图相关的设置等
 */

var FG;
if (!FG)
    FG = {};


FG.DEFAULT_COLORS = ["#7cb5ec", "#fc8d62", "#a6d854", "#ffd92f", "#e78ad2", "#66c2a5", "#e5c494"];
FG.DEFAULT_ROSECOLORS =  ['#4575B4', '#74ADD1', '#ABD9E9', '#FEF4AF', '#FDB568', '#E85438', '#A50026'];

FG.Plotter = function(opts) {
    var this_ = this;

    this.moduleInfo = {
        name: "plotter",
        zhName: "画图器",
        desc: "画图器",
        exportList: [
            'registerPlotDatatype',
            'registerPlotFunc',
            'getPlotDatatype',
            'getPlotFunc'
        ]
    };
    
    if (!!opts && !!opts.app) {
        this.app = opts.app;
    }
    
    this.datatypeDict = {};
    this.plotFuncDict = {};
    
    // // done: 直接使用settinger的内容.
    // this.colors = ["#7cb5ec", "#fc8d62", "#a6d854", "#ffd92f", "#e78ad2", "#66c2a5", "#e5c494"];
    // DX.set('plotColors', this.colors);
    
    // FG.registerSettingCallback('sys', 'plot', function(plotSettings) {
    //     if (!!plotSettings && !!plotSettings.colors) {
    //         this_.colors = plotSettings.colors;
    //         DX.set('plotColors', this_.colors);
    //     }
    // });
    // FG.registerSettingCallback('sys', 'plot.colors', function(colors) {
    //     if (!!colors) {
    //         this_.colors = colors;
    //         DX.set('plotColors', this_.colors);
    //     }
    // });
    
    this.registerPlotDatatype = function(srcTypeName, finalTypeName) { 
        if (!finalTypeName && _.isObject(srcTypeName)) {
            _.extend(this.datatypeDict, srcTypeName);
        } else {
            this.datatypeDict[srcTypeName] = finalTypeName;
        }
    };
    
    this.getPlotDatatype = function(srcTypeName) {
        var res = this.datatypeDict[srcTypeName];
        if (typeof res === 'undefined') {
            res = srcTypeName;
        }
        return res;
    };
    
    this.registerPlotFunc = function(datatype, func, opts) {
        if (!func && _.isObject(datatype)) {
            _.extend(this.plotFuncDict, datatype);
        } else {
            if (!!opts) {
                this.plotFuncDict[datatype] = _.partial(func, _, _, opts);
            } else {
                this.plotFuncDict[datatype] = func;
            }
        }
    };
    
    this.getPlotFunc = function(datatype) {
        return this.plotFuncDict[this.getPlotDatatype(datatype)];
    };
};


